<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/2/20 0020
  Time: 上午 11:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ include file="/common/common.jspf" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>test</title>

</head>
<script type="application/javascript">

    $(document).ready(function(){
         var total=parseInt(0);//总价

        var mingxiorder;

        var dingorder;

        var deskid;

        var deskname;

        var payform;


        $('#tab').datagrid({
            url:'${proPath}/storetable/selectPage.action', // user/select.action
            queryParams:  {tableStatus:"可用"},
            // method:'post',
            //idfield:'productid',
            checkbox: true,
            columns:[[
                {checkbox:true},
                {field:'tableCompanyName',title:'公司名',width:100},
                {field:'tableStoreName',title:'店铺名',width:100},
                {field:'tablePic',title:'二维码',width:100,align:'right'},
                {field:'tableId',title:'ID',width:100},
                {field:'tableNum',title:'餐桌编号',width:100},
                {field:'tableName',title:'餐桌名称',width:100},
                {field:'tableSeatNum',title:'座位数',width:100},
                {field:'tableStatus',title:'餐桌状态',width:100},
                {field:'tableWays',title:'就餐形式',width:100},
                {field:'tableCreate',title:'创建时间',width:100},
                {field:'tableUpdate',title:'更新时间',width:100}
            ]],
            fitColumns:true,
            toolbar: [{
                iconCls: 'icon-add',
                text:'确定',
                handler: function(){
                    var selectrow= $('#tab').datagrid('getSelected');
                    $("#deskid").val(selectrow.tableId);
                    $("#deskname").val(selectrow.tableName);
                    //$("#ordernum").val(row.tableCreate);
                     mingxiorder =(new Date()).valueOf();
                    $("#ordernum").val(mingxiorder);
                    $.ajax({
                        type: "post",
                        url:"${proPath}/storetable/updateDisable.action",
                        data:{tableId: selectrow.tableId},
                        dataType: "json",
                        success: function (data) {
                            alert("餐桌修改完毕")
                            //$('#storeTable').datagrid("getSelected");
                        }
                    });


                  }
            }],
            striped:true,
            rownumbers:true,
            pagination:true,
            pageNumber:10,
            pageside:5,
            pageList:[5,10,15,20,25],

        });
        $('#shop').datagrid({
            url:'${proPath}/seeshop/sees.action', // user/select.action
            checkbox: true,
            columns:[[
                {checkbox:true},
                {field:'headOffice',title:'总公司',width:100},
                {field:'showName',title:'店铺名称',width:100},
                {field:'files',title:'商品图片',width:100,
                    formatter:function (value,row,index) {
                        if(value!=null){
                            return  "<img src='${proPath}/upload/"+value+"' style='width: 40px; height: 40px;'>";
                        }
                    }},
                {field:'shopNumber',title:'店铺编号',width:100},
                {field:'shopName',title:'商品名称',width:100},
                {field:'shopCase',title:'商品状态',width:100},
                {field:'shopPrice',title:'商品价格',width:100},
                {field:'shopType',title:'商品分类',width:100,align:'right'}
            ]],
            toolbar: [{
                iconCls: 'icon-add',
                text:'确定',
                handler: function(){

                    dingorder =(new Date()).valueOf();
                    $("#simpleorder").val(dingorder);//设置订单号

                    var ordermun=$('#ordernum').val();//设置订单明细号

                    deskid=$('#deskid').val();//桌号

                     deskname=$('#deskname').val();//获取餐桌名字

                     payform = $("#payform").find("option:selected").text();//获取支付方式
                    alert(payform)
                    var selectrow= $('#shop').datagrid('getSelected');
                   var html="<tr><td>"+selectrow.shopName+"</td>"+"<td>"+selectrow.shopPrice+"</td><td>1</td></tr>"
                  var html1=document.getElementById('ming').innerHTML;
                    html1+=html;
                    document.getElementById('ming').innerHTML=html1;

                    //加到总价
                    total+=parseInt(selectrow.shopPrice);
                    $("#pay").val(total);

                    $.post(
                        //新增订单明细
                        "${proPath}/order/detailinsert.action",
                        {   goodPrice:selectrow.shopPrice,
                            simpleOrder:mingxiorder,
                            goodName:selectrow.shopName,
                            goodNum:1,
                            deskId:deskid,
                            deskName:deskname,
                            orderNum:dingorder,
                            payForm:payform,
                            orderState:1,
                            goodExitNum:1,
                        },
                        function (data) {
                            $('#bb').datagrid({
                                url:"${proPath}/order/zhengjieshow.action",

                                queryParams: {
                                    simpleOrder:mingxiorder,
                                    orderState:1,
                                },
                                checkbox: true,
                                toolbar: [{
                                    iconCls: 'icon-save',
                                    text:'完成',
                                    handler: function(){
                                        alert('添加');
                                        $.post(
                                            "${proPath}/order/simpleinsert.action",
                                            {   deskId:deskid,
                                                orderNum:mingxiorder,
                                                deskName:deskname,
                                                orderPay:total,
                                                payFrom:payform,
                                                orderState:4,
                                                payed:1,
                                             },
                                            function (data) {
                                                alert("订单生成")
                                                //修改订单状态
                                                parent.$('#win').window('close');
                                                var win = parent.$("iframe[title='订单管理']").get(0).contentWindow;
                                                win.$("#dg").datagrid("reload");
                                            },
                                            "json"
                                        )

                                    }
                                }],
                                columns:[[
                                    {checkbox: true},
                                    {field:'orderNum',title:'订单号',width:100},
                                    {field:'goodNum',title:'商品数量',width:100},
                                    {field:'goodName',title:'商品名字',width:100},
                                    {field:'goodPrice',title:'价格',width:100},
                                    {field:'orderState',title:'菜品状态',width:100},
                                    {field:'payForm',title:'付款形式',width:100},
                                    {field:'orderMessage',title:'备注',width:100,align:'right'}
                                ]],
                                striped:true,
                                rownumbers:true,
                                pagination:true,
                                pageSize:5,
                                pageList:[1,2,3,4,5]
                            });
                            win.$("#bb").datagrid("reload");
                        },
                        "json"
                    )
                   }
            }],
            striped:true,
            rownumbers:true,
            pagination:true,
            pageNumber:10,
            pageside:5,
            pageList:[5,10,15,20,25],
    })


    })
</script>
<body>
<table id="tab"></table>
<table id="shop"></table>



餐桌号:<input id="deskid" type="text" value="" class="easyui-validatebox">
餐桌名字:<input id="deskname" type="text" value="" class="easyui-validatebox">
详细订单号:<input id="ordernum" type="text" value="" class="easyui-validatebox"><br>

订单号：<input id="simpleorder" type="text" class="easyui-validatebox">
付款金额:<input id="pay" type="text" value="" class="easyui-validatebox">
付款方式：<select id="payform" class="easyui-combobox" name="dept" style="width:200px;">
    <option value="aa">微信</option>
    <option>支付宝</option>
    <option>现金</option>
</select>
<br>
<table id="ming" >
    <tr><td>菜名</td><td>价格</td><td>数量</td></tr>
</table>
<table id="bb" ></table>
</body>

</html>
